class Solution {
    public boolean canJump(int[] nums) {
        int n=nums.length-1,ans=0;
        for(int i=0;ans<n&&i<=ans;i++)
            ans=Math.max(ans,i+nums[i]);
        return ans>=n;
    }
}
